/**
 * @Description: NewsController
 * @Author: Mr.Niu
 * @Date: 2022/9/20 17:20
 */
package com.zhiyou.crud.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou.crud.bean.News;
import com.zhiyou.crud.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;
import java.util.List;

@Controller
public class NewsController {
    @Autowired
    NewsService newsService;
    //咨询查询 并把页面数据拿到

    @RequestMapping("/news")
    public String getnews(@RequestParam(value = "pn", defaultValue = "1")Integer pn,Model model,HttpSession session){
        PageHelper.startPage(pn,9);
      List<News> newss= newsService.getallnews();
      model.addAttribute("nss",newss);
        PageInfo page = new PageInfo(newss, 5);
        model.addAttribute("pageInfo", page);
        Integer[] getallnews=newsService.getddj();
        session.setAttribute("ddj", getallnews);
      return "ly-list";
    }
    @RequestMapping("/sss")
    public void sss(HttpSession session, HttpServletResponse response) throws Exception {
        Integer[] getallnews=newsService.getddj();
        session.setAttribute("ddj", getallnews);
        response.setContentType("text/json:charset=utf-8");
        PrintWriter out=response.getWriter();
        String resStr="{\"response\":\"success\"}";
        out.println(resStr);
    }
}
